<?php

/**
 * Description of URL
 *
 * @author user
 */
class URL {

    /**
     * Get Base URL of website
     */
    public static function base_url() {
        return BASEURL;
    }

    /**
     * Get URL site based on path
     *
     * Let base url = 'localhost' and path = 'home/index' this function will
     * return 'localhost/home/index'
     *
     * @param   string  path
     * @return  string
     */
    public static function site($path) {
        return self::base_url() . $path;
    }

    /**
     * Redirect to basepath/$to
     * 
     * @param string $to
     * @param boolean $include_get_parameter include get parameter
     */
    public static function redirect($to, $include_get_parameter = TRUE) {

        if ($include_get_parameter) {
            // compact $_GET
            $get = "?";
            foreach ($_GET as $key => $value) {
                $get .= "$key=$value&";
            }
            $get = rtrim($get, "&");
            if ($get == "?") {
                $get = "";
            }
            header("Location: " . URL::base_url() . $to . $get);
        } else {
            header("Location: " . URL::base_url() . $to);
        }
        die();
    }

    public static function redirect_to_last_path() {
        URL::redirect($_SERVER['last_path']);
    }

}

?>
